package com.j2ee.student.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.j2ee.student.domain.Student;
import com.j2ee.student.service.StudentService;
import com.j2ee.student.util.R;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Student)表控制层
 *
 * @author makejava
 * @since 2022-05-26 15:35:39
 */
@RestController
@RequestMapping("student")
public class StudentController {

/**
 * 服务对象
 */
    @Resource
    private StudentService studentService;

/**
     * 分页查询所有数据
     */

    @RequiresRoles("admin")
    @GetMapping
    public R page(@RequestParam(defaultValue = "1") int current , @RequestParam(defaultValue = "10") int size){
        Page<Student> page=new Page<>(current,size);
        return R.ok().setData(this.studentService.page(page));
    }


/**
 * 通过主键查询单条数据
 */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id){
        return R.ok().setData(this.studentService.getById(id));}

/**
 * 新增数据
 */
    @PostMapping
    public R save(@RequestBody Student student){
        return R.ok().setData(this.studentService.save(student));}

/**
 * 修改数据
 */
    @PutMapping
    public R updateById(@RequestBody Student student){
        return R.ok().setData(this.studentService.updateById(student));}

/**
 * 单条/批量删除数据
 */
    @DeleteMapping
    public R delete(@RequestParam List<Long> id){
        return R.ok().setData(this.studentService.removeByIds(id));}
}

